package cn.edu.scau.cmi.wujiaming.experiment4.client;

import cn.edu.scau.cmi.wujiaming.experiment4.adapter.AdapterOfClass;
import cn.edu.scau.cmi.wujiaming.experiment4.adapter.AdapterOfObject;
import cn.edu.scau.cmi.wujiaming.experiment4.adapter.Target;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Client extends Application {

	@Override
	public void start(Stage arg0) throws Exception {
		// TODO Auto-generated method stub
		BorderPane pane = getPane();

		Scene scene = new Scene(pane);
		arg0.setTitle("实验五-适配器模式");
		arg0.setScene(scene);
		arg0.show();

	}

	public BorderPane getPane() {
		BorderPane pane = new BorderPane();
		GridPane customPane1 = new GridPane();
		Pane customPane2 = new Pane();
		customPane1.setAlignment(Pos.CENTER);
		customPane1.setHgap(40);
		customPane1.setVgap(40);

		TextArea tf = new TextArea();
		tf.setEditable(false);

		Text name = new Text("姓名：吴佳明");
		Text id = new Text("学号：201627010525");

		Button classbt = new Button("类适配器");
		Button objectbt = new Button("对象适配器");

		classbt.setOnAction((ActionEvent e) -> {
			Target ade = new AdapterOfClass();
			tf.setText(ade.output110VInfo());
		});

		objectbt.setOnAction((ActionEvent e) -> {
			Target ade = new AdapterOfObject();
			tf.setText(ade.output110VInfo());
		});

		customPane1.add(name, 0, 0);
		customPane1.add(id, 2, 0);
		customPane1.add(classbt, 0, 2);
		customPane1.add(objectbt, 2, 2);
//		customPane2.getChildren().add(view);

		pane.setLeft(customPane2);
		pane.setCenter(customPane1);
		pane.setBottom(tf);

		return pane;
	}

	public static void main(String[] args) {
		Application.launch(args);
	}

	/**
	 * 用于综合性实验打开界面
	 */
	public void openNewView_adapterOfObject() {
		Stage stage = new Stage();
		Pane pane = getPane();
		stage.setScene(new Scene(pane));
		stage.setTitle("实验四-对象适配器模式");
		stage.show();
	}

	public void openNewView_adapterOfClass() {
		Stage stage = new Stage();
		Pane pane = getPane();
		stage.setScene(new Scene(pane));
		stage.setTitle("实验四-类适配器模式");
		stage.show();
	}
}
